#ifndef HB_CIRCULAR_BUF_H
#define HB_CIRCULAR_BUF_H

#include <iostream>
#include <mutex>

// unsigned int  is 65535, data must be smaller 65535
struct circularBuffer {
    std::mutex m_lock;
    unsigned int m_size;
    unsigned int m_in;
    unsigned int m_out;
    unsigned char *m_buffer;
};

int initCircularBuf(struct circularBuffer *buf, unsigned int size);

void freeCircularBuf(struct circularBuffer *buf);

void clearCircularBuf(struct circularBuffer *buf);

unsigned int getDataCount(struct circularBuffer *buf);

unsigned int getFreeCount(struct circularBuffer *buf);

unsigned int writeCircularBuf(struct circularBuffer *buf, unsigned char *data, unsigned int len);

unsigned int readCircularBuf(struct circularBuffer *buf, unsigned char *data, unsigned int len);
#endif //HB_CIRCULAR_BUF_H